﻿using System.Collections.Generic;
using System.Linq;

namespace Haimen;

internal class FuncDictMaker(
    IEnumerable<WorkshopFuncMain> funcList) {

  public Dictionary<string, WorkshopFuncMain> Make(string funcArg) {
    int prefixEnd = funcArg.IndexOf('_') + 1;
    string prefix = funcArg[..prefixEnd];
    return _funcList.ToDictionary(f => prefix + GetFuncId(f));
  }

  string GetFuncId(WorkshopFuncMain func) {
    string typeName = func.GetType().Name;
    int idStart = "WorkshopFunc".Length;
    return typeName[idStart..];
  }

  readonly IEnumerable<WorkshopFuncMain> _funcList = funcList;
}

internal interface WorkshopFuncMain {
  void Run(EntryArgResult args);
}
